package com.contexticon.TableEditorsRenderers;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.*;
import javax.swing.table.TableCellEditor;

public class SimpleMultiRowCellEditor extends AbstractCellEditor  implements ActionListener, TableCellEditor, FocusListener{

    final JPanel panel;
    private final JButton rowCount;
    private JTextField textField;
    
    public SimpleMultiRowCellEditor() {
        super();
        
        textField = new JTextField();
        textField.addActionListener(this);
        textField.addFocusListener(this);
        //this.setClickCountToStart(1);

        rowCount = new JButton();
        rowCount.setVisible(true);
        panel = new JPanel();
        panel.setSize(300, 100);
        panel.setBackground(Color.RED);
        panel.setOpaque(false);
        panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
        panel.add(rowCount);
        panel.add(textField);
        //panel.addFocusListener(new PanelFocusListener());
        
        //textField.addFocusListener(new PanelFocusListener());

    }

    public void actionPerformed(ActionEvent e) {
    	System.out.println("action happened");
    }
    
    public Component getTableCellEditorComponent(
        final JTable table,final Object val, final boolean isSelected,
        final int row, final int column) {
        return panel;
        //rowCount.setText("1");
        //delegate.setValue(val);
        //editorComponent.requestFocusInWindow();
        //return panel;

    }



	@Override
	public Object getCellEditorValue() {
		// TODO Auto-generated method stub
		return textField.getText();
	}

	@Override
	public void focusGained(FocusEvent e) {
		// TODO Auto-generated method stub
		System.out.println("Focus gained");
		
	}

	@Override
	public void focusLost(FocusEvent e) {
		// TODO Auto-generated method stub\
       	System.out.println("Focus lost");
		
	}
}